﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreData;
using EntityData;
using Helper;
using System.Web.Mvc;
namespace Services
{

    public partial class Merchant_NotifyService
    {
       readonly IMerchant_NotifyEntity entity;
       readonly IMerchantEntity MerchantEntity;
       public Merchant_NotifyService(IMerchant_NotifyEntity entity,IMerchantEntity merchant)
       {
           this.entity = entity;
           this.MerchantEntity = merchant;

       }

       #region Main Method

       /// <summary>
       /// Save 
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public long Save(object _model)
       {
           try
           {
               var obj = (CoreData.Merchant_Notify)_model;
               var id = obj.ID;
               if (id == 0)
               {
                   
                   return entity.Save(obj, Table.Merchant_Notify.ToString());
               }
               else
               {
                   return entity.Update(obj, Table.Merchant_Notify.ToString());
               }
           }
           catch { return -1; }
       }

       /// <summary>
       /// Get by ID
       /// </summary>
       /// <param name="_id"></param>
       /// <returns></returns>
       public CoreData.Merchant_Notify GetByID(long _id)
       {
           try
           {
               return entity.GetById(_id, Table.Merchant_Notify.ToString());
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Merchant_Notify> GetList()
       {
           try
           {
               return entity.GetAll(Table.Merchant_Notify.ToString()).ToList();
           }
           catch { return null; }

       }

       /// <summary>
       /// Get List with Linq
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Merchant_Notify> GetListByLINQ(Func<CoreData.Merchant_Notify, Boolean> _where)
       {
           try
           {
               return entity.GetMany(_where, Table.Merchant_Notify.ToString()).ToList();
           }
           catch { return null; }
       }
       /// <summary>
       /// Get One with Linq
       /// </summary>
       /// <returns></returns>
       public CoreData.Merchant_Notify GetOneByLINQ(Func<CoreData.Merchant_Notify, Boolean> _where)
       {
           try
           {
               return entity.Get(_where, Table.Merchant_Notify.ToString());
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List with search string
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Merchant_Notify> GetList(string _searchstring)
       {
           //search theo tieu chi nao do         
           try
           {
               return entity.GetBySearchString(_searchstring, Table.Merchant_Notify.ToString()).ToList();
           }
           catch { return null; }
       }


       /// <summary>
       /// Delete
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public bool Delete(object _model)
       {
           try
           {
               entity.Delete((CoreData.Merchant_Notify)_model, Table.Merchant_Notify.ToString());
               return true;
           }
           catch { return false; }
       }


       #endregion



        #region Other Method

       public List<SelectListItem> GetListMerchant(string id)
       {
           if (id == null) id = "";
           var lst = new List<SelectListItem>();
           var listcate = MerchantEntity.GetAll(Table.Merchant.ToString());
           var ids = id.Split(',');
           lst.Add(new SelectListItem() { 
                Text ="Select all", Value="0"
           });
           foreach (var c in listcate)
           {
               var item = new SelectListItem();
               item.Text = c.MerchantName;
               item.Value = c.ID.ToString();
               if (ids != null && ids.Count() != 0)
               {
                   var index = Array.IndexOf(ids, c.ID.ToString());
                   if (index >= 0)
                   {
                       item.Selected = true;
                   }
               }
               lst.Add(item);
           }
           if (ids == null || ids.Count() <= 0 || ids[0]=="0")
               lst.First().Selected = true;
           return lst;

       }



        #endregion 
    
    }
         
}
